
/**
 * 图层基类
 */

export default class Layer{
  /**
   * @param{} this.cache overlay合集
   */
  constructor(){
    this._cache = {}
  }

  get cache(){
    return this._cache
  }
  
  /**
   * 
   * @param {*} id 获取单个图层 
   * @returns 
   */
  getOverlay(id){
    return this.cache[id] || undefined
  }

  /**
   * @description 获取所有元素
   * @returns 所有元素合集
   */

  getOverlays(){
    let overlays = []
    Object.keys(this.cache).forEach(overlayId => {
      let overlay = this.cache[overlayId]
      overlays.push(overlay)
    })
    return overlays
  }

  /**
   * @description 遍历所有元素
   * @param {*} method 
   */
  eachOverlays(method){
    Object.keys(this.cache).forEach(overlayId => {
      let overlay = this.cache[overlayId]
      method && method.call(this , overlay)
    })
  }


}